package com.work.rcj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.work.rcj.common.base.BaseController;
import com.work.rcj.common.model.Response;
import com.work.rcj.common.model.page.PageResult;
import com.work.rcj.entity.Visit;
import com.work.rcj.pojo.dto.VisitDto;
import com.work.rcj.pojo.vo.VisitVo;
import com.work.rcj.service.VisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 *  访问记录管理
 *
 * @author rcj
 * @since 2022-02-26
 */
@RestController
@RequestMapping("/visit")
public class VisitController extends BaseController {

    @Autowired
    private VisitService visitService;


    /**
     * 访问记录列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Response<PageResult<VisitVo>> VisitList(VisitDto dto) {
        return Response.success(getDataTable(visitService.selectList(dto)));
    }

    /**
     * 新增访问记录
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody Visit req) {
        visitService.save(req);
        return Response.success();
    }

    /**
     * 修改探望记录
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody Visit req) {
        UpdateWrapper<Visit> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        visitService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除访问记录
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody Visit req) {
        Visit entity = new Visit();
        entity.setId(req.getId());
        entity.setDeleted("1");
        visitService.updateById(entity);
        return Response.success();
    }

    /**
     * 访问记录详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Response<Visit> detail(Long id) {
        Visit Visit = visitService.getById(id);
        return Response.success(Visit);
    }


}

